package com.zues.thread.lock.reent;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 演示ReentrantLock为可重入锁
 * @author zues
 * @date 2/24/2025 10:22 下午
 */
@Slf4j(topic = "c.Demo1")
public class Demo1 {


    private static ReentrantLock lock =new ReentrantLock();

    public static void main(String[] args) {
        lock.lock();
        try{
            log.debug("enter main");
            m1();
        }finally {
            lock.unlock();
        }

    }


    public static void m1(){
        lock.lock();
        try{
            log.debug("enter m1");
            m2();
        }finally {
            lock.unlock();
        }
    }

    public static void m2(){
        lock.lock();
        try{
            log.debug("enter m2");
        }finally {
            lock.unlock();
        }
    }

}
